package com.glodon.paas.document.dao;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.util.Date;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.encoding.Md5PasswordEncoder;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import static com.glodon.paas.document.constant.DocumentConstant.*;
import com.glodon.paas.document.dao.domain.FileInfoEntity;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(value = { "classpath:test-document-dao.xml", "classpath:paas-document-dao-mysql.xml" })
@Ignore
public class FileInfoDaoMySqlIT {

    @Autowired()
    FileDao         fileDao;

    String          DEFAULT_FILE_ID  = "DEFAULT_FILE_ID";
    String          DEFAULT_OWNER_ID = "DEFAULT_OWNER_ID";
    long            createTimeSecons = System.currentTimeMillis() / 1000;

    private Integer FILE_STATUS_DELETED;

    // 文件夹操作,简单操作
    @Test
    public void testSimpleFileCrud() {
        clean();
        // # delete所有数据
        fileDao.cleanByOwnerId(DEFAULT_OWNER_ID);
        // # insert samecreateDefaultFolder
        FileInfoEntity record = newFile(DEFAULT_FILE_ID, DEFAULT_OWNER_ID, FILE_TYPE_FOLDER, "name", "", 0L);
        fileDao.insert(record);
        try {
            fileDao.insert(record);
            fail("should dup key exception");
        } catch (Exception e) {
        }
        // # selectById()
        FileInfoEntity filedb = fileDao.get(DEFAULT_FILE_ID);
        assertEquals(DEFAULT_FILE_ID, filedb.getId());

        // # getFile()
        assertTrue(fileDao.getFiles(DEFAULT_OWNER_ID, record.getName(), new Integer[] { FILE_STATUS_NORMAL },
                                    new Integer[] { FILE_TYPE_FILE }).size() == 0);
        assertTrue(fileDao.getFiles(DEFAULT_OWNER_ID,
                                    record.getName(),
                                    new Integer[] { FILE_STATUS_DELETED, FILE_STATUS_RECYCLE,
                                            FILE_STATUS_RECYCLE_CASCADE }, new Integer[] { FILE_TYPE_FOLDER }).size() == 0);
        assertTrue(fileDao.getFiles(DEFAULT_OWNER_ID, record.getName(), new Integer[] { FILE_STATUS_NORMAL }, null).size() > 0);
        assertNotNull(fileDao.getFileId(DEFAULT_OWNER_ID, record.getName(), new Integer[] { FILE_STATUS_NORMAL },
                                        new Integer[] { FILE_TYPE_FOLDER }));
        // assertEquals(DEFAULT_OWNER_ID, fileDao.getFileOwner(DEFAULT_FILE_ID));
        assertEquals(DEFAULT_OWNER_ID, fileDao.getParentId(DEFAULT_FILE_ID));
        assertTrue(fileDao.getUsedSpace(DEFAULT_OWNER_ID) >= 0);
        assertNotNull(fileDao.getFiles(DEFAULT_OWNER_ID, record.getName(), new Integer[] { FILE_STATUS_NORMAL },
                                       new Integer[] { FILE_TYPE_FOLDER }).get(0));

        // # update status FileName ShareStatus updateSizeRevisionNum
        fileDao.updateStatus(DEFAULT_FILE_ID, FILE_STATUS_NORMAL);
        fileDao.updateFileName(DEFAULT_FILE_ID, "newName", DEFAULT_OWNER_ID);
        fileDao.updateShareType(DEFAULT_FILE_ID, SHARE_TYPE_SHARED);
        fileDao.updateSizeNumCount(DEFAULT_FILE_ID, 100, 10, 1, new Date());
        fileDao.updateDataBagId(DEFAULT_FILE_ID, "dataBagId");
        filedb = fileDao.get(DEFAULT_FILE_ID);
        assertEquals(FILE_STATUS_NORMAL, filedb.getDeletedStatus());
        assertEquals("newName", filedb.getFullName());
        assertTrue(filedb.isShared());
        assertTrue(filedb.getSize() == 100);
        assertTrue(filedb.getActiveRevision() == 10);
        assertEquals("dataBagId", filedb.getDataBagId());

        // # getFile() error
        filedb = fileDao.getFile(DEFAULT_FILE_ID + "x", null, null);
        assertNull(filedb);
        // # delete
        int rtint = fileDao.delete(DEFAULT_FILE_ID);
        assertEquals(rtint, 1);
        filedb = fileDao.get(DEFAULT_FILE_ID);
        assertNull(filedb);
        clean();
    }

    @Test
    public void testReadMethod() {
        clean();
        initData();

        assertEquals("t10",
                     fileDao.getFiles(DEFAULT_OWNER_ID, "testFile_01.txt", new Integer[] { FILE_STATUS_NORMAL },
                                      new Integer[] { FILE_TYPE_FILE }).get(0).getId());
        assertEquals("t04",
                     fileDao.getFiles("t03", "testFile_01.txt", new Integer[] { FILE_STATUS_NORMAL },
                                      new Integer[] { FILE_TYPE_FILE }).get(0).getId());
        assertEquals("t01",
                     fileDao.getFiles(DEFAULT_OWNER_ID, "testFolder_01", new Integer[] { FILE_STATUS_NORMAL },
                                      new Integer[] { FILE_TYPE_FOLDER }).get(0).getId());
        assertEquals("t03",
                     fileDao.getFiles("t02", "testFolder_01", new Integer[] { FILE_STATUS_NORMAL },
                                      new Integer[] { FILE_TYPE_FOLDER }).get(0).getId());
        // 查询
        // fileDao.selectByComplex(DEFAULT_OWNER_ID, DEFAULT_OWNER_ID, type, deletedStatus, orderProperty, orderType,
        // startIndex, count)

        // files in root/folder
        assertEquals(6, fileDao.getFiles(DEFAULT_OWNER_ID, null, null, null).size());

        // normal files in root/folder
        assertEquals(4, fileDao.getFiles(DEFAULT_OWNER_ID, null, new Integer[] { FILE_STATUS_NORMAL }, null).size());
        // normal folder in root/folder
        assertEquals(2,
                     fileDao.getFiles(DEFAULT_OWNER_ID, null, new Integer[] { FILE_STATUS_NORMAL },
                                      new Integer[] { FILE_TYPE_FOLDER }).size());
        assertEquals(1,
                     fileDao.getFiles(DEFAULT_OWNER_ID, "testFolder_01", new Integer[] { FILE_STATUS_NORMAL },
                                      new Integer[] { FILE_TYPE_FOLDER }).size());
        // normal doc in root/folder
        assertEquals(2,
                     fileDao.getFiles(DEFAULT_OWNER_ID, null, new Integer[] { FILE_STATUS_NORMAL },
                                      new Integer[] { FILE_TYPE_FILE }).size());
        assertEquals(1,
                     fileDao.getFiles(DEFAULT_OWNER_ID, "testFile_01.txt", new Integer[] { FILE_STATUS_NORMAL },
                                      new Integer[] { FILE_TYPE_FILE }).size());

        // deleted files in root/folder
        assertEquals(2,
                     fileDao.getFiles(DEFAULT_OWNER_ID, null,
                                      new Integer[] { FILE_STATUS_RECYCLE, FILE_STATUS_RECYCLE_CASCADE }, null).size());
        // deleted folder in root/folder
        assertEquals(1,
                     fileDao.getFiles(DEFAULT_OWNER_ID, null,
                                      new Integer[] { FILE_STATUS_RECYCLE, FILE_STATUS_RECYCLE_CASCADE },
                                      new Integer[] { FILE_TYPE_FOLDER }).size());
        assertEquals(1,
                     fileDao.getFiles(DEFAULT_OWNER_ID, "testFolder_03",
                                      new Integer[] { FILE_STATUS_RECYCLE, FILE_STATUS_RECYCLE_CASCADE },
                                      new Integer[] { FILE_TYPE_FOLDER }).size());
        // deleted doc in root/folder
        assertEquals(1,
                     fileDao.getFiles(DEFAULT_OWNER_ID, null,
                                      new Integer[] { FILE_STATUS_RECYCLE, FILE_STATUS_RECYCLE_CASCADE },
                                      new Integer[] { FILE_TYPE_FILE }).size());
        assertEquals(1,
                     fileDao.getFiles(DEFAULT_OWNER_ID, "testFile_03.pdf",
                                      new Integer[] { FILE_STATUS_RECYCLE, FILE_STATUS_RECYCLE_CASCADE },
                                      new Integer[] { FILE_TYPE_FILE }).size());

        // assertEquals(2, fileDao.count(DEFAULT_OWNER_ID, DEFAULT_OWNER_ID, FILE_TYPE_FOLDER, FILE_STATUS_NORMAL));
        // assertEquals(2, fileDao.count(DEFAULT_OWNER_ID, DEFAULT_OWNER_ID, FILE_TYPE_FILE, FILE_STATUS_NORMAL));
        // assertEquals(1, fileDao.count(DEFAULT_OWNER_ID, DEFAULT_OWNER_ID, FILE_TYPE_FOLDER, FILE_STATUS_RECYCLE));
        // assertEquals(1, fileDao.count(DEFAULT_OWNER_ID, DEFAULT_OWNER_ID, FILE_TYPE_FILE, FILE_STATUS_RECYCLE));
        // assertEquals(3, fileDao.count(DEFAULT_OWNER_ID, DEFAULT_OWNER_ID, FILE_TYPE_FILE, null));
        // assertEquals(3, fileDao.count(DEFAULT_OWNER_ID, DEFAULT_OWNER_ID, FILE_TYPE_FOLDER, null));
        // assertEquals(4, fileDao.count(DEFAULT_OWNER_ID, DEFAULT_OWNER_ID, null, FILE_STATUS_NORMAL));
        // assertEquals(2, fileDao.count(DEFAULT_OWNER_ID, DEFAULT_OWNER_ID, null, FILE_STATUS_RECYCLE));
        // assertEquals(6, fileDao.count(DEFAULT_OWNER_ID, DEFAULT_OWNER_ID, null, null));
        // assertEquals(15,fileDao.count(DEFAULT_OWNER_ID, null, null, null));
        //
        // assertEquals(4, fileDao.count(DEFAULT_OWNER_ID, null, FILE_TYPE_FOLDER, FILE_STATUS_NORMAL));
        // assertEquals(6, fileDao.count(DEFAULT_OWNER_ID, null, FILE_TYPE_FILE, FILE_STATUS_NORMAL));
        // assertEquals(1, fileDao.count(DEFAULT_OWNER_ID, null, FILE_TYPE_FOLDER, FILE_STATUS_RECYCLE));
        // assertEquals(3, fileDao.count(DEFAULT_OWNER_ID, null, FILE_TYPE_FILE, FILE_STATUS_RECYCLE));
        //
        // assertEquals(2, fileDao.count("xxx", "t06", FILE_TYPE_FILE, FILE_STATUS_NORMAL));
        // assertEquals(0, fileDao.count("xxx", "t06", FILE_TYPE_FOLDER, FILE_STATUS_NORMAL));

        assertEquals(FILE_STATUS_RECYCLE.intValue(),
                     fileDao.getFile("t14", new Integer[] { FILE_STATUS_RECYCLE, FILE_STATUS_RECYCLE_CASCADE }, null).getDeletedStatus().intValue());
        assertEquals(FILE_STATUS_RECYCLE_CASCADE.intValue(),
                     fileDao.getFile("t15", new Integer[] { FILE_STATUS_RECYCLE, FILE_STATUS_RECYCLE_CASCADE }, null).getDeletedStatus().intValue());
        assertEquals("t13",
                     fileDao.getFile("t13", new Integer[] { FILE_STATUS_RECYCLE, FILE_STATUS_RECYCLE_CASCADE }, null).getId());
        assertEquals(1800, fileDao.getUsedSpace(DEFAULT_OWNER_ID));
        assertEquals("t06", fileDao.getParentId("t07"));

        fileDao.updateStatus("t09", FILE_STATUS_NORMAL);
        assertEquals(1800, fileDao.getUsedSpace(DEFAULT_OWNER_ID));
        fileDao.delete("t09");
        assertEquals(1500, fileDao.getUsedSpace(DEFAULT_OWNER_ID));

        clean();
    }

    /*
     * @Test public void testSelectByComplex(){ System.out.println("start complex"); clean(); initData();
     * List<FileInfoEntity> list = null; // 测试排序createTime list = fileDao.selectByComplex(DEFAULT_OWNER_ID, "t02",
     * FILE_TYPE_FOLDER, null,FILE_STATUS_NORMAL, "createTime", 1, 0, 100);
     * assertTrue(list.get(0).getCreateTime().getTime() < list.get(1).getCreateTime().getTime()); list =
     * fileDao.selectByComplex(DEFAULT_OWNER_ID, "t02", FILE_TYPE_FOLDER, null,FILE_STATUS_NORMAL, "createTime", 3, 0,
     * 100); assertTrue(list.get(0).getCreateTime().getTime() < list.get(1).getCreateTime().getTime()); list =
     * fileDao.selectByComplex(DEFAULT_OWNER_ID, "t02", FILE_TYPE_FOLDER, null,FILE_STATUS_NORMAL, "createTime", null,
     * 0, 100); assertTrue(list.get(0).getCreateTime().getTime() < list.get(1).getCreateTime().getTime()); list =
     * fileDao.selectByComplex(DEFAULT_OWNER_ID, "t02", FILE_TYPE_FOLDER, null,FILE_STATUS_NORMAL, "createTime", -1, 0,
     * 100); assertTrue(list.get(0).getCreateTime().getTime() > list.get(1).getCreateTime().getTime()); // 测试排序name list
     * = fileDao.selectByComplex(DEFAULT_OWNER_ID, "t02", FILE_TYPE_FOLDER, null,FILE_STATUS_NORMAL, "name", 1, 0, 100);
     * assertTrue(list.get(0).getName().compareTo(list.get(1).getName()) < 0); list =
     * fileDao.selectByComplex(DEFAULT_OWNER_ID, "t02", FILE_TYPE_FOLDER, null,FILE_STATUS_NORMAL, "name", 3, 0, 100);
     * assertTrue(list.get(0).getName().compareTo(list.get(1).getName()) < 0); list =
     * fileDao.selectByComplex(DEFAULT_OWNER_ID, "t02", FILE_TYPE_FOLDER, null,FILE_STATUS_NORMAL, "name", null, 0,
     * 100); assertTrue(list.get(0).getName().compareTo(list.get(1).getName()) < 0); list =
     * fileDao.selectByComplex(DEFAULT_OWNER_ID, "t02", FILE_TYPE_FOLDER, null,FILE_STATUS_NORMAL, "name", -1, 0, 100);
     * assertTrue(list.get(0).getName().compareTo(list.get(1).getName()) > 0); // 测试排序extension list =
     * fileDao.selectByComplex(DEFAULT_OWNER_ID, DEFAULT_OWNER_ID, FILE_TYPE_FILE, null,FILE_STATUS_NORMAL, "extension",
     * 1, 0, 100); assertTrue(list.get(0).getExtension().compareTo(list.get(1).getExtension()) < 0); list =
     * fileDao.selectByComplex(DEFAULT_OWNER_ID, DEFAULT_OWNER_ID, FILE_TYPE_FILE, null,FILE_STATUS_NORMAL, "extension",
     * 3, 0, 100); assertTrue(list.get(0).getExtension().compareTo(list.get(1).getExtension()) < 0); list =
     * fileDao.selectByComplex(DEFAULT_OWNER_ID, DEFAULT_OWNER_ID, FILE_TYPE_FILE, null,FILE_STATUS_NORMAL, "extension",
     * null, 0, 100); assertTrue(list.get(0).getExtension().compareTo(list.get(1).getExtension()) < 0); list =
     * fileDao.selectByComplex(DEFAULT_OWNER_ID, DEFAULT_OWNER_ID, FILE_TYPE_FILE, null,FILE_STATUS_NORMAL, "extension",
     * -1, 0, 100); assertTrue(list.get(0).getExtension().compareTo(list.get(1).getExtension()) > 0); // 分页
     * assertEquals(2, fileDao.selectByComplex(DEFAULT_OWNER_ID, DEFAULT_OWNER_ID, FILE_TYPE_FOLDER,
     * null,FILE_STATUS_NORMAL, null, -1, 0, 100).size()); assertEquals(1, fileDao.selectByComplex(DEFAULT_OWNER_ID,
     * DEFAULT_OWNER_ID, FILE_TYPE_FOLDER, null,FILE_STATUS_NORMAL, null, -1, 0, 1).size()); assertEquals(1,
     * fileDao.selectByComplex(DEFAULT_OWNER_ID, DEFAULT_OWNER_ID, FILE_TYPE_FOLDER, null,FILE_STATUS_NORMAL, null, -1,
     * 1, 100).size()); // 测试参数parentId="" assertEquals(2, fileDao.selectByComplex(DEFAULT_OWNER_ID, DEFAULT_OWNER_ID,
     * FILE_TYPE_FOLDER, null,FILE_STATUS_NORMAL, null, -1, 0, 100).size()); // 测试参数oenerId!="" assertEquals(2,
     * fileDao.selectByComplex(null, "t02", FILE_TYPE_FOLDER, null,FILE_STATUS_NORMAL, null, -1, 0, 100).size()); //
     * 测试参数type=folder,NORMAL assertEquals(2, fileDao.selectByComplex(DEFAULT_OWNER_ID, DEFAULT_OWNER_ID,
     * FILE_TYPE_FOLDER, null,FILE_STATUS_NORMAL, null, -1, 0, 100).size()); assertEquals(2,
     * fileDao.selectByComplex(null, "t02", FILE_TYPE_FOLDER, null,FILE_STATUS_NORMAL, null, -1, 0, 100).size()); //
     * 测试参数type=folder,RECYCLE assertEquals(1, fileDao.selectByComplex(DEFAULT_OWNER_ID, DEFAULT_OWNER_ID,
     * FILE_TYPE_FOLDER, null, FILE_STATUS_RECYCLE, null, -1, 0, 100).size()); // 测试参数type=folder,NORMAL & RECYCLE
     * assertEquals(3, fileDao.selectByComplex(DEFAULT_OWNER_ID, DEFAULT_OWNER_ID, FILE_TYPE_FOLDER, null, null, null,
     * -1, 0, 100).size()); // 测试参数type=file,NORMAL assertEquals(2, fileDao.selectByComplex(DEFAULT_OWNER_ID,
     * DEFAULT_OWNER_ID, FILE_TYPE_FILE, null, FILE_STATUS_NORMAL, null, -1, 0, 100).size()); assertEquals(0,
     * fileDao.selectByComplex(null, "t02", FILE_TYPE_FILE, null, FILE_STATUS_NORMAL, null, -1, 0, 100).size());
     * assertEquals(2, fileDao.selectByComplex(null, "t06", FILE_TYPE_FILE, null, FILE_STATUS_NORMAL, null, -1, 0,
     * 100).size()); // 测试参数type=file,RECYCLE assertEquals(1, fileDao.selectByComplex(DEFAULT_OWNER_ID,
     * DEFAULT_OWNER_ID, FILE_TYPE_FILE, null, FILE_STATUS_RECYCLE, null, -1, 0, 100).size()); assertEquals(1,
     * fileDao.selectByComplex(null, "t06", FILE_TYPE_FILE, null, FILE_STATUS_RECYCLE, null, -1, 0, 100).size()); //
     * 测试参数type=file,NORMAL & RECYCLE assertEquals(3, fileDao.selectByComplex(DEFAULT_OWNER_ID, DEFAULT_OWNER_ID,
     * FILE_TYPE_FILE,null, null, null, -1, 0, 100).size()); assertEquals(3, fileDao.selectByComplex(null, "t06",
     * FILE_TYPE_FILE, null, null, null, -1, 0, 100).size()); // 测试参数type=file,级联删除 assertEquals(3,
     * fileDao.selectByComplex(DEFAULT_OWNER_ID, DEFAULT_OWNER_ID, FILE_TYPE_FILE, null, null, null, -1, 0,
     * 100).size()); assertEquals("t14", fileDao.selectByComplex(null, "t13", FILE_TYPE_FILE, null, FILE_STATUS_RECYCLE,
     * null, -1, 0, 100).get(0).getId()); assertEquals("t15", fileDao.selectByComplex(null, "t13", FILE_TYPE_FILE, null,
     * FILE_STATUS_RECYCLE_CASCADE, null, -1, 0, 100).get(0).getId()); assertEquals(2, fileDao.selectByComplex(null,
     * "t13", FILE_TYPE_FILE, null, null, null, -1, 0, 100).size()); clean(); System.out.println("end complex"); }
     */
    /*
     * 初始化数据如下： id, fil --------------------------------------- t01, d testFolder_01 t02, d testFolder_02 t03, d
     * testFolder_01 t04, - testFile_01.txt 100kb t05, - testFile_02.txt 200kb t06, d testFolder_02 t07, -
     * testFile_01.txt 100kb t08, - testFile_02.txt 200kb t09, - testFile_03.txt 300kb deleted t10, - testFile_01.txt
     * t11, - testFile_02.pdf t12, - testFile_03.pdf deleted t13, d testFolder_03 deleted t14, - testFile_01.txt 主动删除
     * t15, - testFile_02.txt 级联删除
     */
    public void initData() {
        // fileDao.insert(newFile(id, parentId, type, name, extension, size));
        fileDao.insert(newFile("t01", DEFAULT_OWNER_ID, FILE_TYPE_FOLDER, "testFolder_01", "", 0L));
        fileDao.insert(newFile("t02", DEFAULT_OWNER_ID, FILE_TYPE_FOLDER, "testFolder_02", "", 0L));
        fileDao.insert(newFile("t03", "t02", FILE_TYPE_FOLDER, "testFolder_01", "", 0L));
        fileDao.insert(newFile("t04", "t03", FILE_TYPE_FILE, "testFile_01", "txt", 100L));
        fileDao.insert(newFile("t05", "t03", FILE_TYPE_FILE, "testFile_02", "txt", 200L));

        fileDao.insert(newFile("t06", "t02", FILE_TYPE_FOLDER, "testFolder_02", "", 0L));
        fileDao.insert(newFile("t07", "t06", FILE_TYPE_FILE, "testFile_01", "txt", 100L));
        fileDao.insert(newFile("t08", "t06", FILE_TYPE_FILE, "testFile_02", "txt", 200L));
        fileDao.insert(newFile("t09", "t06", FILE_TYPE_FILE, "testFile_03", "txt", 300L));
        fileDao.updateStatus("t09", FILE_STATUS_RECYCLE);
        fileDao.insert(newFile("t10", DEFAULT_OWNER_ID, FILE_TYPE_FILE, "testFile_01", "txt", 100L));
        fileDao.insert(newFile("t11", DEFAULT_OWNER_ID, FILE_TYPE_FILE, "testFile_02", "pdf", 200L));
        fileDao.insert(newFile("t12", DEFAULT_OWNER_ID, FILE_TYPE_FILE, "testFile_03", "pdf", 300L));
        fileDao.updateStatus("t12", FILE_STATUS_RECYCLE);
        fileDao.insert(newFile("t13", DEFAULT_OWNER_ID, FILE_TYPE_FOLDER, "testFolder_03", "", 0L));
        fileDao.insert(newFile("t14", "t13", FILE_TYPE_FILE, "testFile_01", "txt", 100L));
        fileDao.insert(newFile("t15", "t13", FILE_TYPE_FILE, "testFile_01", "txt", 200L));
        fileDao.updateStatus("t13", FILE_STATUS_RECYCLE);
        fileDao.updateStatus("t14", FILE_STATUS_RECYCLE);
        fileDao.updateStatus("t15", FILE_STATUS_RECYCLE_CASCADE);
    }

    private void clean() {
        fileDao.cleanByOwnerId(DEFAULT_OWNER_ID);
    }

    /**
     * @param id
     * @param parentId
     * @param type
     * @param name
     * @param extension
     * @param size
     * @param createTimeSecond 创建时间秒
     * @return
     */
    private FileInfoEntity newFile(String id, String parentId, Integer type, String name, String extension, Long size) {
        FileInfoEntity record = new FileInfoEntity();
        record.setOwnerId(DEFAULT_OWNER_ID);
        record.setId(id);
        record.setParentId(parentId);
        record.setType(type);
        record.setName(name);
        record.setExtension(extension);
        record.setSize(size);
        record.setCount(0);
        record.setCreateTime(new Date((createTimeSecons++) * 1000));
        record.setActiveRevision(1);
        return record;
    }

    private Md5PasswordEncoder md5PasswordEncoder;

    @Before
    public void setUp() {
        md5PasswordEncoder = new Md5PasswordEncoder();
    }

    @Test
    @Ignore
    public void testInsertFiles() {
        for (int i = 0; i < 100000; i++) {
            String email = i + "@test.com";
            String ownerId = md5PasswordEncoder.encodePassword(email, null);
            for (int j = 0; j < 100; j++) {
                FileInfoEntity record = new FileInfoEntity();
                record.setOwnerId(ownerId);
                record.setId(ownerId + j);
                record.setParentId(ownerId);
                record.setType(1);
                // record.setName("testFile_"+j);
                record.setName("testFile_" + j);
                record.setActiveRevision(1);
                record.setExtension("");
                record.setSize(0L);
                record.setCount(0);
                fileDao.insert(record);
            }

        }

    }
}
